﻿using ChatServer.Servers;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

//注册SignalR服务
builder.Services.AddSignalR().AddHubOptions<ChatHub>(options =>
{
    options.MaximumReceiveMessageSize = 100 * 1024 * 1024; //100MB
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

//使用路由
app.UseRouting();
app.UseHttpsRedirection();
app.UseAuthorization();

app.UseAuthorization();

app.MapControllers();

//映射路由
app.UseEndpoints(endpoints =>
{
    //启用SignalR中间件，并且设置当客户端通过SignalR请求“/myhub”这个路径的时候，由ChatHub进行处理。
    endpoints.MapHub<ChatHub>("/signalchat");
});

app.Run();
